package com.group.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.mapper.UserNumberMapper;
import com.group.pojo.UserNumber;
import com.group.service.UserNumberService;
import com.group.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author group
 * @since 2021-09-06
 */
@RestController
@RequestMapping("/group/user-number")
public class UserNumberController {

    @Autowired
    private UserNumberService userNumberService;


        @ApiOperation(value = "查询全部学号表数据")
        @RequestMapping("/findAllUserNumber")
        public R findAllUserNumber(UserNumber userNumber, Integer pageNo, Integer pageSize){
            if(pageNo==null){
                pageNo = 1;
            }
            if(pageSize==null){
                pageSize = 5;
            }
            //启动分页
            PageHelper.startPage(pageNo,pageSize);
            List<UserNumber> list = userNumberService.findAllUserNumber();
            PageInfo<UserNumber> pageInfo = new PageInfo<>(list);
            return R.ok().data("pageinfo",pageInfo);
        }

        @ApiOperation("添加学号表内容")
        @RequestMapping("/addUserNumber")
        public R addUserNumber(@RequestBody UserNumber userNumber){
//            userNumber.setUsernumberid(3);
//            userNumber.setStudentid("201724113321");
            boolean flag = userNumberService.addUserNumber(userNumber);
            return flag ? R.ok() : R.error();
        }

        @ApiOperation("删除学号表内容")
        @RequestMapping("/delUserNumber")
        public R delUserNumber(UserNumber userNumber){
            boolean flag = userNumberService.deleteUserNumber(userNumber);
            return flag ? R.ok() : R.error();
        }

        @ApiOperation("修改学号表内容")
        @RequestMapping("/updateUserNumber")
        public R updateUserNumber(@RequestBody UserNumber userNumber){
//            userNumber.setUsernumberid(3);
//            userNumber.setStudentid("201924113321");
            boolean flag = userNumberService.updateUserNumber(userNumber);
            return flag ? R.ok() : R.error();
        }



}

